#!/usr/bin/perl -w

# Licensed under the GNU Lesser General Public License, version 2.1 (LGPL-2.1)
# Full text is available at:
#
#    http://www.gnu.org/licenses/lgpl-2.1.txt
#
# This file is part of cyg-get.
#
#    cyg-get is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Lesser General Public License as
#    published by the Free Software Foundation, either version 2.1 of
#    the License, or (at your option) any later version.
#
#    cyg-get is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU Lesser General Public
#    License along with cyg-get.
#
#    If not, see <http://www.gnu.org/licenses/>.

use strict;
use warnings;

use Getopt::Long;
use Pod::Usage;

use Cygwin::Db;

my $usage = '';
my $help = '';
my $man = '';

my $opts = GetOptions( "usage" => \$usage,
                       "help|?" => \$help,
                       man => \$man)
   or pod2usage(2);

pod2usage(1) if $help;
pod2usage(-exitstatus => 0, -verbose => 2) if $man;

pod2usage(-verbose => 99, -sections => "DESCRIPTION")
  if $usage;

if( !@ARGV ) {
    push( @ARGV, ".*" );
}

my $db = Cygwin::Db->new();

print join("\n", sort($db->find(@ARGV)) );
print "\n";

__END__

=head1 NAME

cyg-get-list - Lists packages installed in cygwin

=head1 SYNOPSIS

cyg-get list [regexp [regexp2 [...]]]

  regexp        Regular expression defining the package names
                to find.  Will repeat search for each regular
                expression given.

=head1 OPTIONS

=over 8

=item B<--usage>

Lists installed packages

=item B<--man>

Prints the manual page and exits

=back

=head1 DESCRIPTION

Lists packages installed.

=cut
